<template>
  <div class="question_list">
    <scroller class="scroller" noDataText="没有更多了" :on-refresh="refresh" :on-infinite="infinite">
      <ques-item v-for="(item,index) in queslist" :key="index" :item="item" ></ques-item>
    </scroller>
  </div>
</template>
<script>
import quesItem from "@/components/quesItem";

export default {
  data(){
	  return{
      page:0,
      fqPromoteType:this.$route.query.fqPromoteType,
      fqId:this.$route.query.fqId,
      queslist:[],
      ismore:true,
    }
  },
  components:{
    quesItem
  },
  created(){
    this.getQueslist();
  },
  // mounted() {
  //   window.addEventListener('scroll', this.scrollLoad);
  // },
  // destroyed() {
  //   window.removeEventListener('scroll', this.scrollLoad)
  // },
  methods:{
    getQueslist(done){
      if(this.fqPromoteType){
        this.$http.fetchGet("getFlashList", {
          fqPromoteType:this.fqPromoteType,
          offset:this.page*10,
          limit: 10
        }).then(({ data }) => {
          if(!this.page){this.queslist = data.question}
          else{
            this.queslist = this.queslist.concat(data.question);
          };
          done && done(!data.question.length);
        });
      }
    },
    refresh(done) {
      this.page = 0;
      this.getQueslist(done);
    },
    infinite(done) {
      this.page++;
      this.getQueslist(done);
    },
    scrollLoad(){
      var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
      var windowHeight = window.outerHeight;
      var documentHei =document.body.scrollHeight;
      if(documentHei <= scrollTop + windowHeight +150 ){
        if(!this.ismore){
          return;
        }
        this.page++;
        this.getQueslist();
      }

    }
  }
}
</script>

<style scoped lang="less">

</style>

